package com.zhong.bmob.server;

import com.zhong.bmob.inter.IFindRequestAddFriendsMessageDown;
import com.zhong.bmob.model.AddFriendsMessage;

import java.util.List;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

/**
 * Created by 俊峰 on 2017/5/27.
 */

public class FindRequestAddFriendsMessage {
    public static void findRequestAddFriendsMessage(String from, String to, IFindRequestAddFriendsMessageDown findRequestAddFriendsMessageDown){
        final IFindRequestAddFriendsMessageDown iFindRequestAddFriendsMessageDown = findRequestAddFriendsMessageDown;
        BmobQuery<AddFriendsMessage> query = new BmobQuery<>();
        query.addWhereEqualTo("from", from);
        query.addWhereEqualTo("to", to);
        query.findObjects(new FindListener<AddFriendsMessage>() {
            @Override
            public void done(List<AddFriendsMessage> list, BmobException e) {
                if (e == null){
                   iFindRequestAddFriendsMessageDown.findSuccess(list.get(0));
                }else {
                    iFindRequestAddFriendsMessageDown.findFailed(e);
                }
            }
        });
    }
}
